package common

import (
	"myapp/model"

	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/postgres"
)

var DB *gorm.DB

func InitDB() *gorm.DB {
	dsn := "host=localhost user=postgres password=123456 dbname=sbject port=5432 sslmode=disable TimeZone=Asia/Shanghai"
	db, _ := gorm.Open("postgres", dsn)
	db.AutoMigrate(&model.PortCompany{})
	db.AutoMigrate(&model.CargoCompany{})
	db.AutoMigrate(&model.Cargo{})
	db.AutoMigrate(&model.Outcar{})
	db.AutoMigrate(&model.Incar{})
	return db
}

//获取数据库实例
func GetDB() *gorm.DB {
	return DB
}
